package com.daylive.service;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.daylive.model.Reports;
import com.daylive.util.StringUtil;

@Service  
public class TaskJob {  
	@Autowired
	private ReportsService reportsService;
	
    public void dayEvent() {  
    	int  addUser =reportsService.addUserCount(StringUtil.getStrDate());
    	int  addLive = reportsService.addLiveCount(StringUtil.getStrDate());
    	int  addUserOnline = reportsService.addUserOnlineCount(StringUtil.getStrDate());
    	int  minutes = reportsService.getMinutes(StringUtil.getStrDate());
    	
    	Reports  reports = new Reports();
    	reports.setTime(StringUtil.getStrDate());
    	reports.setNewUsers(addUser);
    	reports.setLives(addLive);
    	reports.setParticipants(addUserOnline);
    	reports.setMinutes(minutes);
    	reportsService.addReports(reports);
    }  
	public static HttpSession getSession() {
		HttpSession session = null;
		try {
			session = getRequest().getSession();
		} catch (Exception e) {
		}
		return session;
	}

	public static HttpServletRequest getRequest() {
		ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder
				.getRequestAttributes();
		return attrs.getRequest();
	}
	private void clearSession() {
		getSession().invalidate();
	}
}